setwd("/scratch/jc227089/evostochPBS/")


R0<-seq(2, 20, 2)
pop.reps<-20

script.file<-"/home/jc227089/scratch/evo-dispersal/evostoch/evostoch_Allee.R"
fname<-"evostoch_Allee"
for (jj in 1:length(R0)){
	for (ii in 1:pop.reps) {

		fid<-paste(R0[jj], ii, sep="_")
		##create the sh file
		zz = file(paste(fname, fid,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd $PBS_O_WORKDIR\n',file=zz)
		cat('module load R\n', file=zz)
		cat("R CMD BATCH --no-save --no-restore '--args repn=",ii, " R0=",R0[jj], "' ", sep="", file=zz)
		cat(script.file, " ", paste(fname, fid,'.Rout',sep=''), "\n", sep="",file=zz)
		cat('##################################\n',file=zz)
		close(zz)
				
		#submit the job
		system(paste("qsub -m n ", paste(fname, fid,".sh",sep=""),sep=""))
	}
}
